﻿<form id="frmBXJGEquipmentEquipmentInfo" class="frm-container">
    <input type="hidden" name="id" value="0" />
    <table class="frm-box">
        <tr>
            <th>设备名称</th>
            <td>
                <input name="name" class="easyui-textbox" data-options=" required:true, validType:'length[1,200]',prompt:'设备名称'" />
            </td>
        </tr>
        <tr>
            <th>硬件码</th>
            <td>
                <input name="hardwareCode" class="easyui-textbox" data-options=" required:true, validType:'length[1,200]',prompt:'设备内部的唯一标识'" />
            </td>
        </tr>
        <tr>
            <th>所属区域</th>
            <td>
                <!--<input name="areaId" class="easyui-combotree"
                         data-options="url:abp.appPath+'api/services/app/bxjgbaseinfoAdministrative/GettreeForSelect',
                         queryParams: { forType: 4 }" />-->
                <input name="areaId" value="0" />
            </td>
        </tr>
        <tr>
            <th>经度</th>
            <td>
                <input name="longitude" type="text" class="easyui-numberbox" data-options="min:0,precision:6,prompt:'经度'">
            </td>
        </tr>
        <tr>
            <th>纬度</th>
            <td>
                <input name="latitude" type="text" class="easyui-numberbox" data-options="min:0,precision:6,prompt:'纬度'">
            </td>
        </tr>
    </table>
</form>
<script>
    (function () {
        let m = 'BXJGEquipmentEquipmentInfo';
        let $dlg = $('#dlg' + m);
        let $frm = $dlg.find('form');
        let $name = $frm.find('[name="name"]');
        let $cls = $frm.find('[name="areaId"]');

        let id = $dlg.data('id');
        var clsId = $dlg.data('clsId');

        var initParentTask = $.Deferred();
        var initFormTask = $.Deferred();

        $dlg.data('clickSave', function () {
            if (!$frm.form('validate'))
                return;

            var postData = $frm.serializeJSON();
            var defer;
            if (id) {
                defer = abp.services.app[abp.utils.toCamelCase(m)].update(postData).done(function (d) {
                    abp.notify.success(abp.localization.bxjgUtils('修改') + abp.localization.bxjgUtils('成功') + '!');
                    onSaved('onUpdated');
                });
            } else {
                defer = abp.services.app[abp.utils.toCamelCase(m)].create(postData).done(function (d) {
                    abp.notify.success(abp.localization.bxjgUtils('新增') + abp.localization.bxjgUtils('修改') + '!');
                    onSaved('onAdded');
                });
            }
            abp.ui.setBusy($dlg, defer);
        });
        function onSaved(funcName) {
            var f = $dlg.data(funcName);
            if (f)
                f();
        }

        $cls.combotree({
            url: abp.appPath + 'api/services/app/bxjgbaseinfoAdministrative/GetTreeForSelect',
            queryParams: { forType: 4, parentText: '全国' },
            prompt: abp.localization.bxjgUtils('全国'),
            onLoadSuccess: function (node, data) {
                initParentTask.resolve();
            },
            loadFilter: function (data, parent) {
                data = $.fn.combotree.defaults.loadFilter(data, parent);
                if (data && data[0])
                    data[0].id = 0;//奇怪这里用'0' 与输入口默认值对应不起来
                return data;
            }
        });

        if (id) {
            initFormTask = abp.services.app[abp.utils.toCamelCase(m)].get({ id: id }).done(function (d) {
                $frm.form('load', d);
            });
        } else {
            $cls.combotree('setValue', clsId);
            initFormTask.resolve();
        }

        abp.ui.setBusy($dlg, $.when(initFormTask, initParentTask));

        setTimeout(function () {
            $name.next('span').find('input').focus();
        }, 0);

    })();
</script>
